<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      // 1-方法 indexOf
      var arr = [1, 2, 4, 5, 2, 5, 6, 8, 6, 1]
      var arr1 = []
      for (var i = 0; i < arr.length; i++) {
        if (arr1.indexOf(arr[i]) === -1) {
          arr1.push(arr[i])
        }
      }
      console.log(arr) // [1, 2, 4, 5, 2, 5, 6, 8, 6, 1]
      console.log(arr1) //[1, 2, 4, 5, 6, 8]

      // 2-方法 利用对象
      var arr2 = [1, 2, 4, 5, 2, 5, 6, 8, 6, 1]
      var obj = {}
      for (var i = 0; i < arr2.length; i++) {
        obj[arr[i]] = 'aa'
      }
      console.log(obj) //{1: 'aa', 2: 'aa', 4: 'aa', 5: 'aa', 6: 'aa', 8: 'aa'}
      var arr3 = []
      for (var i in obj) {
        arr3.push(i - 0)
      }
      console.log(arr3) // [1, 2, 4, 5, 6, 8]

      // 3-方法  set方法
      var arr4 = [1, 2, 4, 5, 2, 5, 6, 8, 6, 1]
      var set1 = new Set(arr4)
      console.log(set1) //Set(6) {1, 2, 4, 5, 6,1}
      // 把 Set 转换为数组 Array.from
      var arr5 = Array.from(set1)
      console.log(arr5) //[1, 2, 4, 5, 6, 8]
    </script>
  </body>
</html>
